<?php
include '../Module/CategoryModule.php';
$CaModule=new CategoryModule();
if(isset($_REQUEST["action"])){
    switch ($_REQUEST["action"]){
        case"add":
            $_type		=isset($_REQUEST["_type"])?$_REQUEST["_type"]:"";
            $name		=isset($_REQUEST["name"])?EndcodeStr($_REQUEST["name"]):"";
            $level		=isset($_REQUEST["level"])?EndcodeStr($_REQUEST["level"]):"";
            if($CaModule->insertCategory($_type,$name,$level)){
                echo "true";
            }else{
                echo "Error: Please, Check level of category.<br/>".$CaModule->error;
            }
            break;
        case"edit":
            $_type		=isset($_REQUEST["_type"])?$_REQUEST["_type"]:"";
            $id                 =isset($_REQUEST["id"])?$_REQUEST["id"]:"";
            $name		=isset($_REQUEST["name"])?EndcodeStr($_REQUEST["name"]):"";
            $lv                 =isset($_REQUEST["level"])?EndcodeStr($_REQUEST["level"]):"";
            if($CaModule->updateCategory($name, $lv, $id)){
                echo "true";
            }else{
                echo "Error<br/>".$CaModule->error;
            }
            break;
        case"delete":
            $_type		=isset($_REQUEST["_type"])?$_REQUEST["_type"]:"";
            $id                 =isset($_REQUEST["id"])?$_REQUEST["id"]:"";
            if($CaModule->deleteCategory($id)){
                echo "Delete Success.";
                JO_location();
                break;
            }else{
                echo "Error<br/>".$CaModule->error;
            }
            break;
    }    
}
?>